package com.xh.baselibrary.callback;

import androidx.lifecycle.MediatorLiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.xh.baselibrary.model.RequestErrBean;


import retrofit2.Retrofit;

/**
 * @author xh on 2019/8/19
 */
public class BaseViewModel extends ViewModel {




    private MutableLiveData<RequestErrBean> errorLiveData;//请求失败
    private MutableLiveData<Boolean> showDialogLiveData;//加载框


    public MutableLiveData<RequestErrBean> getErrorLiveData() {
        if (null == errorLiveData) {
            errorLiveData = new MutableLiveData<>();
        }
        return errorLiveData;
    }

    public MutableLiveData<Boolean> getShowDialogLiveData() {
        if (null == showDialogLiveData) {
            showDialogLiveData = new MutableLiveData<>();
        }
        return showDialogLiveData;
    }
    public <T> T get(Retrofit retrofit,Class<T> t){
        return retrofit.create(t);
    }

    public <T> MediatorLiveData<T> creatLiveData(MediatorLiveData<T> mediatorLiveData){

        if(mediatorLiveData==null){
            return  mediatorLiveData=new MediatorLiveData<>();
        }
        return mediatorLiveData;
    }

}
